package com.hongye.controller;

import java.util.List;

import com.hongye.app.model.BuyerStatisticsModel;
import com.hongye.app.model.EmployeeManageModel;
import com.hongye.util.Utils;
import com.jfinal.core.Controller;
/**
 * 员工管理相关
 * @author Administrator
 *
 */
public class EmployeeManageController extends Controller{
	
	public EmployeeManageController() {
		
	}
	
	/**
	 * 获取员工列表
	 * @author lifuqiang
	 * 2017-3-20
	 */
	public void employeeManageView(){
		List<EmployeeManageModel> list = EmployeeManageModel.dao.getEmployeeList();
		for(EmployeeManageModel em : list){
			long invite_num = BuyerStatisticsModel.getInviteNum(em.getStr("employee_num"));
			em.put("invite_num", invite_num);
		}
		this.setAttr("employeelist", list);
		this.renderJsp("employeeManageView.jsp");
	}
	
	/**
	 * 添加新员工
	 * @author lifuqiang
	 * 2017-3-20
	 */
	public void addNewEmployee(){
		int department = this.getParaToInt("department");
		String place = this.getPara("place");
		String e_name = this.getPara("e_name");
		int e_sex = this.getParaToInt("e_sex");
		String e_phone = this.getPara("e_phone");
		String employee_num = this.getPara("employee_num");
		boolean isExist = EmployeeManageModel.isExistEmployee(employee_num);
		String rs= null;
		if(isExist){
			rs= "re";
		}else{
			boolean boo = EmployeeManageModel.dao.addNewEmployee(department, place, e_name, e_sex, e_phone, employee_num);
			if(boo){
				rs = "suc";
			}else{
				rs = "fal";
			}
		}
		this.renderText(rs);
	}
	
	/**
	 * 获取员工邀请的店铺列表
	 * @author lifuqiang
	 * 2017-3-20
	 */
	public void employeeDetail(){
		String employee_num = this.getPara("employee_num");
		List<BuyerStatisticsModel> list = BuyerStatisticsModel.getBS_By_EmployeeNum(employee_num);
		this.setAttr("employee_num", employee_num);
		this.setAttr("employeelist", list);
		this.renderJsp("employeeDetail.jsp");
	}
	
	/**
	 * 获取员工邀请的店铺列表(筛选)
	 * @author lifuqiang
	 * 2017-3-21
	 */
	public void screen(){
		String startTime = this.getPara("startTime");
		String endTime = this.getPara("endTime");
		String employee_num = this.getPara("employee_num");
		List<BuyerStatisticsModel> list = null;
		String time_start = null;
		String time_end = null;
		if(startTime.equals("") || startTime == null){
			startTime = "01/01/2017";
		}
		if(endTime.equals("") || startTime == null){
			time_end = Utils.getDate().toString();
		}else{
			time_end = Utils.sdfTosdf(endTime, "MM/dd/yyyy", "yyyy-MM-dd HH:mm:ss");
		}
		time_start = Utils.sdfTosdf(startTime, "MM/dd/yyyy", "yyyy-MM-dd HH:mm:ss");
		list = BuyerStatisticsModel.getBS_ByScreen(time_start, time_end, employee_num);
		this.setAttr("employeelist", list);
		this.setAttr("employee_num", employee_num);
		this.renderJsp("employeeDetail.jsp");
	}
	
}
